FIND_PACKAGE( SWIG REQUIRED )
INCLUDE( ${SWIG_USE_FILE} )

FIND_PACKAGE( PythonInterp )
FIND_PACKAGE( PythonLibs )

EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -B -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print numpy.distutils.misc_util.get_numpy_include_dirs()[0]"
    RESULT_VARIABLE NUMPY_PROCESS
    OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
    OUTPUT_STRIP_TRAILING_WHITESPACE)
FIND_PATH( PYTHON_NUMPY_INCLUDE_DIR numpy/ndarrayobject.h HINTS ${NUMPY_INCLUDE_DIR} )

FIND_PATH( PYTHON_PYCAIRO_INCLUDE_DIR pycairo.h HINTS ${PYTHON_INCLUDE_DIR}/pycairo /usr/local/include/pycairo )

INCLUDE_DIRECTORIES( 
    ${PYTHON_INCLUDE_PATH} 
    ${PYTHON_NUMPY_INCLUDE_DIR}
    ${CAIRO_INCLUDE_DIR}
    ${PYTHON_PYCAIRO_INCLUDE_DIR} )

INCLUDE_DIRECTORIES(
    ${CUDA_INCLUDE_DIRS}
    ${PROJECT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR} )

FILE( GLOB headers RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ../oz/*.h )

SET(CMAKE_SWIG_FLAGS "")
SET_SOURCE_FILES_PROPERTIES( pyoz.i PROPERTIES CPLUSPLUS ON )
SET_SOURCE_FILES_PROPERTIES( pyoz.i PROPERTIES SWIG_FLAGS "-DOZAPI" )
SET( SWIG_MODULE_pyoz_EXTRA_DEPS ${headers} )

SWIG_ADD_MODULE( pyoz python pyoz.i numpy.h numpy.cpp )
SOURCE_GROUP( src REGULAR_EXPRESSION "c$|cpp$|hpp$|h$|cu$|py$|i$" )
SOURCE_GROUP( generated REGULAR_EXPRESSION "cxx$|pyoz.py$" )

SWIG_LINK_LIBRARIES( pyoz liboz ${PYTHON_LIBRARIES} )

ADD_CUSTOM_COMMAND( TARGET _pyoz POST_BUILD
    COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/pyoz.py" .
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$(ConfigurationName))
